<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>后台登录</title>
    <link rel="stylesheet" href="./src/css/bootstrap.min.css">
    <link rel="stylesheet" href="./src/css/style.min.css">
    <script type="text/javascript" src="./src/js/jquery-3.3.1.min.js"></script>
</head>

<body class="page-login-body">
    <div class="page-login-wrap">
        <div class="login-inner">
            <img src="./src/img/logo.png" alt="logon" class="logo">
            <div class="login-bg-box">
                <h3 class="tit">刷宝宝管理后台</h3>
                <form id="login-form" method="post" onsubmit="return false;">
                <ul class="login-list list-unstyled">
                    <li>
                        <div class="form-group">
                            <input id="username" name="username" type="text" class="form-control form-control-lg" placeholder="请输入用户名">
                        </div>
                    </li>
                    <li>
                        <div class="form-group">
                            <input id="password" name="password" type="password" class="form-control form-control-lg" placeholder="请输入密码">
                        </div>
                    </li>
                    <!-- <li>
                        <div class="form-group">
                            <input type="text" class="form-control  form-control-lg code" placeholder="请输入验证码">
                            <img src="http://www.qianku.net.cn/api/imcode/checkcode.php" alt="" style="height:48px; vertical-align: middle;">

                        </div>
                    </li> -->
                    <!-- <li>
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" id="defaultCheck1" checked>
                            <label class="form-check-label" for="defaultCheck1">
                                记住密码
                            </label>
                        </div>
                    </li> -->
                    <li>
                        <div class="form-group">
                            <button class="btn btn-primary btn-lg btn-block" onclick="login(this)">登录</button>
                        </div>
                    </li>
                    <li class="text-left" id="info" style="color: red;line-height: 50px" >
                    </li>
                    <li class="text-center">
                        版本号：v0.10
                    </li>
                </ul>
                </form>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript">

	//localStorage.removeItem("token");
	/* var user = localStorage.getItem("user");
	console.log(user);
	if (user != null && user.trim().length != 0) {
		location="/manager/admin/index.html";
		
	} */
	$.ajax({
		url:"/qk_login/haveSession",
		type:'get',
		dataType:'json',
		success:function(data){
			var val = data.state;
			if(val=="yes"){
				location="/manager/admin/index.html";
			}
		}
	});
	
	function login(obj) {
		$(obj).attr("disabled", true);

		var username = $.trim($('#username').val());
		var password = $.trim($('#password').val());
		if (username == "" || password == "") {
			$("#info").html('*用户名或者密码不能为空');
			$(obj).attr("disabled", false);
		} else {
			
			$.ajax({
				type : 'post',
				url : '/qk_login/login',
				data : $("#login-form").serialize(),
				success : function(data) {
					$("#info").html("");
					localStorage.setItem("user", data);
					top.location.href = '/manager/admin/index.html';
				},
				error : function(xhr, textStatus, errorThrown) {
					var msg = xhr.responseText;
					var response = JSON.parse(msg);
					$("#info").html("*"+response.message);
					$(obj).attr("disabled", false);
				}
			});

		}
	}
</script>
</html>